function [ distance ] = getTransitionProfileDistances( cellANumber, cellBNumber, copyNumbers, window )
%Find the distance between copy number transition profiles for cells a and
%b, to be used to create a new phylogenetic tree
    
    profileA = getTransitionProfile(cellANumber, copyNumbers);
    profileB = getTransitionProfile(cellBNumber, copyNumbers);
    
    %search for all transitions along profile A within some window near the
    %same site in profile B. If the transition doesn't exist within the
    %window, incremement the difference between the cells 
    
    %The advantage of this is that single copy number change events aren't
    %magnified too much 
   
    %ex: 223333322 22222222 have a pairwise edit distance of 5 but only
    %have a difference of 2 in terms of their copy # transitions. (2->3/nothing and
    %3->2/nothing)
    
    %window = 3;
    distanceA = 0;
    distanceB = 0;

    if profileA == profileB
        distance = 0;   
        return;
    end
    
    L = length(profileA);
    n_reps = 2*window+1;
    %repeats profile A n_reps times, in one long column
    profileA_repeated = repmat(  [profileA ; zeros(n_reps,1)], 1, n_reps);
    %reshapes profileA_repeated 
    profileA_repeated_shifted = reshape( profileA_repeated(1:(n_reps*(L+n_reps-1))) , L+n_reps-1, n_reps );
    profileB_repeated_middle =  repmat(  [zeros(window,1) ; profileB ; zeros(window,1)], 1, n_reps);
    % min (A, [], dim) returns the smallest elements along the dimension of
    % A specified by dim (dim 2 is column wise) 
    % For example, this would return the smallest element in each row of the
    % the difference matrix
    distance = nnz(sparse(min( abs(profileA_repeated_shifted - profileB_repeated_middle), [], 2)));
    %fprintf('The distance between this pair of cells is %d', distance);
    
%     for site=1:length(profileA)
%         %if there is a change (ie the transition code is nonzero)
%         if profileA(site)~=0
%             transitionCode = profileA(site);
%             if foundTransition(transitionCode,profileB,window,site) ~= 1
%                 distanceA = distanceA + 1;
%             end
%         end
%     end
%     
%     for site=1:length(profileB)
%         %if there is a change (ie the transition code is nonzero)
%         if profileB(site)~=0
%             transitionCode = profileB(site);
%             if foundTransition(transitionCode,profileA,window,site) ~= 1
%                 distanceB = distanceB + 1;
%             end
%         end
%     end
%     
%     distance = distanceA + distanceB/2;
end
